import zipfile
import uuid
import os
import rarfile
def un_file_notype(file_path, target_path, file_type):
    """
    解压文件
    :param file_path:
    :param target_path:
    :param file_type:
    :return:
    """
    listName = []
    fileName = {}
    filedir = {}
    no_pdf = 1
    if file_type == 'zip':
        fzip = zipfile.ZipFile(file_path, 'r')
        for fz in fzip.namelist():
            # fz = str(fz)
            # gg = fz.encode(encoding="cp437")
            # kk = gg.decode(encoding="cp437")
            # print(gg)
            # # print(kk)
            new_name_zip = str(uuid.uuid1()) + '.' + str(fz).split('.')[-1]
            listName.append(new_name_zip)
            f_new = os.path.join(target_path, new_name_zip)
            file = open(f_new, 'wb')
            kp = fzip.read(fz)
            # mm = unicodedata(fz, 'cp936').decode('utf-8')
            file.write(kp)
            file.close()
            fileName[fz] = new_name_zip
            filedir[fz] = os.path.getsize(f_new)
        os.remove(file_path)

    if file_type == 'rar':
        frar = rarfile.RarFile(file_path, 'r')
        for fr in frar.namelist():
            new_name_rar = str(uuid.uuid1()) + '.' + str(fr).split('.')[-1]
            listName.append(new_name_rar)
            f_new = os.path.join(target_path, new_name_rar)
            file = open(f_new, 'wb')
            file.write(frar.read(fr))
            file.close()
            fileName[fr] = new_name_rar
            filedir[fr] = os.path.getsize(f_new)
        os.remove(file_path)
    # print(filedir)

    return fileName, filedir, listName


if __name__ == "__main__":
    pass